#include "EbnNetParamManager.h"
#include <math.h>

CEbnNetParamManager::CEbnNetParamManager()
{
    mExhibitionOfModule = DEFAULT_EXHIBITION_OF_MODULE;
    mInhibitionOfModule = DEFAULT_INHIBITION_OF_MODULE;
    mExhibitionOfState = DEFAULT_EXHIBITION_OF_STATE;
    mInertiaOfActivation = DEFAULT_INERTIA_OF_ACTIVATION;
    mActivationThreshold = DEFAULT_ACTIVATION_THRESHOLD;
    mExecutabilityThreshold = DEFAULT_EXECUTABILITY_THRESHOLD;
    mThresholdDecay = DEFAULT_THRESHOLD_DECAY;
    mUpperBoundOfActivationThreshold = DEFAULT_ACTIVATION_THRESHOLD;

    mSigmoidParamK = DEFAULT_GAIN;
    mSigmoidParamSigma = DEFAULT_SIGMA;

}

CEbnNetParamManager::~CEbnNetParamManager()
{

}

void CEbnNetParamManager::setExhibitionOfModule(float exhibitionParam)
{
    mExhibitionOfModule = exhibitionParam;
}

void CEbnNetParamManager::setInhibitionOfModule(float inhibitionParam)
{
    mInhibitionOfModule = inhibitionParam;
}

void CEbnNetParamManager::setExhibitionOfState(float exhibitionParam)
{
    mExhibitionOfState = exhibitionParam;
}

void CEbnNetParamManager::setInertiaOfActivation(float inertia)
{
    mInertiaOfActivation = inertia;
}

void CEbnNetParamManager::setActivationThreshold(float threshold)
{
    mActivationThreshold = threshold;
}

void CEbnNetParamManager::setExecutabilityThreshold(float threshold)
{
    mExecutabilityThreshold = threshold;
}

void CEbnNetParamManager::setThresholdDecay(float decay)
{
    mThresholdDecay = decay;
}

void CEbnNetParamManager::setUpperBoundOfActivationThreshold(float upper)
{
    mUpperBoundOfActivationThreshold = upper;
}

float CEbnNetParamManager::getExhibitionOfModule(void)
{
    return mExhibitionOfModule;
}

float CEbnNetParamManager::getInhibitionOfModule(void)
{
    return mInhibitionOfModule;
}

float CEbnNetParamManager::getExhibitionOfState(void)
{
    return mExhibitionOfState;
}

float CEbnNetParamManager::getInertiaOfActivation(void)
{
    return mInertiaOfActivation;
}

float CEbnNetParamManager::getActivationThreshold(void)
{
    return mActivationThreshold;
}

float CEbnNetParamManager::getExecutabilityThreshold(void)
{
    return mExecutabilityThreshold;
}

float CEbnNetParamManager::getThresholdDecay(void)
{
    return mThresholdDecay;
}

float CEbnNetParamManager::getUpperBoundOfActivationThreshold(void)
{
    return mUpperBoundOfActivationThreshold;
}

bool CEbnNetParamManager::parametersValidation(void)
{
    if ((mExhibitionOfModule <= 0 || mExhibitionOfModule > 1)
            || (mInhibitionOfModule <= 0 || mInhibitionOfModule > 1)
            || (mInertiaOfActivation <= 0 || mInertiaOfActivation > 1)
            || (mActivationThreshold < 0)
            || (mThresholdDecay < 0)
            || (mUpperBoundOfActivationThreshold < 0))
    {
        return false;
    }

    return true;
}

void CEbnNetParamManager::setSigmoidParams(float k, float sigma)
{
    mSigmoidParamK = k;
    mSigmoidParamSigma = sigma;
}

float CEbnNetParamManager::sigmoidTransferFunction(float value)
{
    return 1 / (1 + exp(mSigmoidParamK * (mSigmoidParamSigma - value)));

}

void CEbnNetParamManager::updateThresholdDecaying(void)
{
    mActivationThreshold = mActivationThreshold * (1 - mThresholdDecay);
}

void CEbnNetParamManager::resetThresholdDecaying(void)
{
    mActivationThreshold = mUpperBoundOfActivationThreshold;
}

